package com.example.chapter3_1.service.iml;

import com.example.chapter3_1.dao.UserDao;
import com.example.chapter3_1.entity.User;
import com.example.chapter3_1.service.LoginService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class LoginServiceIml implements LoginService {
    @Autowired
    UserDao userDao;
    
    @Override
    public boolean login(String username, String password) {
        try {
            User user = userDao.getUserByName(username);
            if (user != null) {
                log.info("登录成功");
                return true;
            }
            log.info("账号密码错误");
            return false;
        } catch (Exception e) {
            log.error("登录过程发生错误: ", e);
            return false;
        }
    }
}
